#import "PointOfInterest.h"

/**
 * A PointOfInterest is an object representing a single point of 
 * interest.
 *
 * Conforms to the PersistentDataType protocol.
 *
 * @author      Justin Hollander
 * @version     0.7.0
 * @since       0.1.0
 * @see         PersistentDataType
 */
@implementation PointOfInterest

@synthesize category;
@synthesize overlayImagePath;
@synthesize isSelected;

/**
 * Initialize the point of interest.
 *
 * @return  the initialized point of interest
 */
-(id) init{
	if (self = [super init]) {
		self.name = @"";
	}
					
	return self;
}

/**
 * Initialize the point of interest with given information.
 *
 * @param nm        the name of the point of interest
 * @param location  location of the point of interest
 * @param cat       the category of the point of interest
 * @return          the initialized point of interest with details
 */
-(id) initWithDetails:(NSString*)nm point:(GPSLocation*)location category:(NSString*)cat 
			  overlay:(NSString*)pinOverlay selected:(BOOL)selectedState{
	if (self = [super initWithDetails:nm point:location]){
		self.category = cat;
		self.overlayImagePath = pinOverlay;
		self.isSelected = selectedState;
	}
	
	return self;
}

/**
 * Initialize the point of interest given another one.
 *
 * @param poi  the other point of interest with which to initialize
 * @return     the initialized point of interest 
 */
-(id) initWithPOI:(PointOfInterest*)poi{
	if (self = [super initWithDetails:poi.name point:poi.loc]) {
		self.category = poi.category;
		self.overlayImagePath = poi.overlayImagePath;
		self.isSelected = poi.isSelected;
	}
	
	return self;
}

/**
 * Initializes the point of interest from archive.
 *
 * @param coder  the NSCoder used for decoding
 * @return       the point of interest decoded from archive
 */
- (id)initWithCoder:(NSCoder*)coder {
	if ((self = [super init]) && ([coder allowsKeyedCoding])){
		[super initWithCoder:coder];
		self.category = [coder decodeObjectForKey:@"POICategory"]; //get buildingname
		self.overlayImagePath = [coder decodeObjectForKey:@"OverlayImagePath"];
		self.isSelected = [coder decodeBoolForKey:@"SelectedState"];
		
	}
	
	return self;
}

/**
 * Encodes the point of interest for archiving options.
 *
 * @param coder  the NSCoder used for encoding
 */
-(void)encodeWithCoder:(NSCoder*)coder{
	if ([coder allowsKeyedCoding]) {
		[super encodeWithCoder:coder];
		[coder encodeObject:self.category forKey:@"POICategory"];
		[coder encodeObject:self.overlayImagePath forKey:@"OverlayImagePath"];
		[coder encodeBool:self.isSelected forKey:@"SelectedState"];
	}
}

/**
 * Compute a unique key for the point of interest.
 *
 * @return  the unique key
 */
- (NSString*)getKey {
	return [self.name stringByAppendingString:self.category]; 
}

/**
 * Deallocate the point of interest.
 */
- (void)dealloc {
	[category release];
	[super dealloc];
}

@end
